package com.atguigu.res;

import lombok.Data;
import lombok.experimental.Accessors;

@Data
@Accessors(chain = true)//链式风格调用
public class ResultData<T>{
    private Integer code;//状态码
    private String message;//错误信息
    private T data;// 数据
    private long timestamp;//时间戳,设置调用的时间
    private String traceId;//调用链的id

    public ResultData() {
        this.timestamp = System.currentTimeMillis();//设置时间戳,只要调用结果类就会调用时间戳方法
    }
    public static <T> ResultData<T> success(T data) {
        ResultData<T> resultData = new ResultData<>();
        resultData.setCode(ResultCodeEnum.SUCCESS.getCode());
        resultData.setMessage(ResultCodeEnum.SUCCESS.getMessage());
        resultData.setData(data);
        return resultData;
    }
    public static <T> ResultData<T> fail(Integer code , String message){
        ResultData<T> resultData = new ResultData<>();
        resultData.setCode(code);
        resultData.setMessage(message);
        return resultData;
    }
}
